package com.hexus.eve.entities;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.hexus.eve.utils.MarketGroupUtils;

@Entity
@Table(name="invMarketGroups")
public class MarketGroup extends EveEntity{
	private static final String DB_TABLE_NAME = "dbo.invMarketGroups";
	private static final String NAME_COLUMN = "marketGroupName";
	private static final String DESCRIPTION_COLUMN = "description";
	
	@Id	
	@Column(name="marketGroupID")
	private Integer id;
	@Column(name="marketGroupName")
	private String name;
	@Column(name="parentGroupID")
	private Integer parentId;
	
	private String description;
	
	public MarketGroup clone() {
		MarketGroup result = new MarketGroup();
		result.setDescription(getDescription());
		result.setHasTypes(getHasTypes());
		result.setIcon(getIcon());
		result.setId(getId());
		result.setName(getName());
		result.setParentId(getParentId()); 
		return result;
	}
	
	@ManyToOne
	@JoinColumn(name="iconID")
	private Icon icon;
	
	private Boolean hasTypes;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getParentId() {
		return parentId;
	}
	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Boolean getHasTypes() {
		return hasTypes;
	}
	public void setHasTypes(Boolean hasTypes) {
		this.hasTypes = hasTypes;
	}
	public Icon getIcon() {
		return icon;
	}
	public void setIcon(Icon icon) {
		this.icon = icon;
	}
	public List<MarketGroup> getParentsAsList(){
		return MarketGroupUtils.getInstance().getAllRelatedItems(this, MarketGroupUtils.PARENTS);
	}
	
	@Override
	public String getTableName() {		
		return DB_TABLE_NAME;
	}

	@Override
	public void translate(Map<String, String> translationValues, Locale locale) {
		if(translationValues.containsKey(NAME_COLUMN)) {
			setName(translationValues.get(NAME_COLUMN));
		}	
		if(translationValues.containsKey(DESCRIPTION_COLUMN)) {
			setDescription(translationValues.get(DESCRIPTION_COLUMN));
		}
	}	
}
